#coding=utf-8
#Boa:Dialog:DlgToolkitShaiWang

import wx

def create(parent):
    return DlgToolkitShaiWang(parent)

[wxID_DLGTOOLKITSHAIWANG, wxID_DLGTOOLKITSHAIWANGBTNCALCULATER, 
 wxID_DLGTOOLKITSHAIWANGBTNWIRETABLE, 
] = [wx.NewId() for _init_ctrls in range(3)]

class DlgToolkitShaiWang(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DLGTOOLKITSHAIWANG,
              name=u'DlgToolkitShaiWang', parent=prnt, pos=wx.Point(869, 211),
              size=wx.Size(400, 417), style=wx.DEFAULT_DIALOG_STYLE,
              title=u'\u7b5b\u7f51\u5de5\u5177\u7bb1')
        self.SetClientSize(wx.Size(392, 383))
        self.SetFont(wx.Font(12, wx.SWISS, wx.NORMAL, wx.BOLD, False,
              u'\u6977\u4f53_GB2312'))
        self.SetBackgroundColour(wx.Colour(128, 255, 128))

        self.btnWireTable = wx.Button(id=wxID_DLGTOOLKITSHAIWANGBTNWIRETABLE,
              label=u'\u4e1d\u53f7\u5bf9\u7167\u8868', name=u'btnWireTable',
              parent=self, pos=wx.Point(16, 96), size=wx.Size(128, 24),
              style=0)
        self.btnWireTable.Bind(wx.EVT_BUTTON, self.OnBtnWireTableButton,
              id=wxID_DLGTOOLKITSHAIWANGBTNWIRETABLE)

        self.btnCalculater = wx.Button(id=wxID_DLGTOOLKITSHAIWANGBTNCALCULATER,
              label=u'\u8ba1\u7b97\u5668', name=u'btnCalculater', parent=self,
              pos=wx.Point(16, 56), size=wx.Size(93, 26), style=0)
        self.btnCalculater.Bind(wx.EVT_BUTTON, self.OnBtnCalculaterButton,
              id=wxID_DLGTOOLKITSHAIWANGBTNCALCULATER)

    def __init__(self, parent):
        self._init_ctrls(parent)
        
    def OnBtnWireTableButton(self, event):
        #self.EndModal(wx.ID_OK)
        
        png = wx.Image(u'./res/丝号对照表.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        #panel = wx.Panel(self.GetParent(), -1)
        #wx.StaticBitmap(panel, -1, png, (10, pos), (png.GetWidth(), png.GetHeight()))
        
##        # PopupTransientWindow，位置不太好，所以改用dialog
##        win = wx.PopupTransientWindow(self)
##
##        pngWireTable = wx.StaticBitmap(win, -1, png)
##        win.SetSize(pngWireTable.GetBestSize())
##        
##        pos = self.btnWireTable.ClientToScreen( (0,0) )
##        sz =  self.btnWireTable.GetSize()
##        win.Position(pos, (0, sz[1]))
##        
##        win.Popup()

        self.EndModal(wx.ID_OK)
        dlg = wx.Dialog(self.GetParent(), -1, u'丝号对照表')
        pngWireTable = wx.StaticBitmap(dlg, -1, png)
        dlg.SetClientSize(pngWireTable.GetBestSize())
        dlg.Centre()
        dlg.ShowModal()

    def OnBtnCalculaterButton(self, event):
        import os
        self.EndModal(wx.ID_OK)
        #self.Close()
        os.startfile('calc')
        
##        import subprocess
##        #self.EndModal(wx.ID_OK)
##        self.Close()
##        #subprocess.call('calc')
        
##        try:
##            retcode = subprocess.call("calc.exe", shell=False)
##            if retcode < 0:
##                print >>sys.stderr, "Child was terminated by signal", -retcode
##            else:
##                print >>sys.stderr, "Child returned", retcode
##        except OSError, e:
##            print >>sys.stderr, "Execution failed:", e
    
        
        
